import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    perms: ['GET /aaa','POST /bbb']     will control the page perms (you can set multiple perms)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'home',
    children: [
      {
        path: 'home',
        component: () => import('@/views/home/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', noCache: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'userManage',
    meta: {
      title: '用户管理',
      icon: 'user'
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/user/user'),
        name: 'user',
        meta: {
          perms: ['GET /admin/user/list'],
          title: '用户列表',
          noCache: true
        }
      },
      {
        path: 'address',
        component: () => import('@/views/user/address'),
        name: 'address',
        meta: {
          perms: ['GET /admin/address/list'],
          title: '收货地址',
          noCache: true
        }
      },
      {
        path: 'Collection',
        component: () => import('@/views/user/Collection'),
        name: 'Collection',
        meta: {
          // perms: ['GET /admin/Collection/list'],
          title: '用户收藏',
          noCache: true
        },
      },
      {
        path: 'footprint',
        component: () => import('@/views/user/footprint'),
        name: 'footprint',
        meta: {
          // perms: ['GET /admin/Collection/list'],
          title: '用户足迹',
          noCache: true
        },
      },
      {
        path: 'history',
        component: () => import('@/views/user/history'),
        name: 'history',
        meta: {
          // perms: ['GET /admin/Collection/list'],
          title: '搜索历史',
          noCache: true
        },
      },
      {
        path: 'feedback',
        component: () => import('@/views/user/feedback'),
        name: 'feedback',
        meta: {
          // perms: ['GET /admin/Collection/list'],
          title: '意见反馈',
          noCache: true
        },
      }
    ]
  },

  {
    path: '/mall',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'mallManage',
    meta: {
      title: '商城管理',
      icon: 'shopping'
    },
    children: [
      {
        path: 'region',
        component: () => import('@/views/malls/region'),
        name: 'region',
        meta: {
          perms: ['POST /admin/region/list'],
          title: '行政区域',
          noCache: true
        }
      },
      {
        path: 'brand',
        component: () => import('@/views/malls/brand'),
        name: 'brand',
        meta: {
          perms: ['POST /admin/brand/list', 'POST /admin/brand/create', 'POST /admin/brand/update', 'POST /admin/brand/delete'],
          title: '品牌制造商',
          noCache: true
        }
      },
      {
        path: 'commodity',
        component: () => import('@/views/malls/commodity'),
        name: 'commodity',
        meta: {
          // perms: ['GET /admin/brand/list', 'POST /admin/brand/create', 'GET /admin/brand/read', 'POST /admin/brand/update', 'POST /admin/brand/delete'],
          title: '商品类目',
          noCache: true
        }
      },
      {
        path: 'order',
        component: () => import('@/views/malls/order'),
        name: 'order',
        meta: {
          // perms: ['GET /admin/brand/list', 'POST /admin/brand/create', 'GET /admin/brand/read', 'POST /admin/brand/update', 'POST /admin/brand/delete'],
          title: '订单管理',
          noCache: true
        }
      },
      {
        path: 'problem',
        component: () => import('@/views/malls/problem'),
        name: 'problem',
        meta: {
          // perms: ['GET /admin/brand/list', 'POST /admin/brand/create', 'GET /admin/brand/read', 'POST /admin/brand/update', 'POST /admin/brand/delete'],
          title: '常见问题',
          noCache: true
        }
      },

    ]
  },
  {
    path: '/goods',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'goodsManage',
    meta: {
      title: '商品管理',
      icon: 'theme'
    },
    children: [
      {
        path: 'commodityList',
        component: () => import('@/views/goods/commodityList'),
        name: 'commodityList',
        meta: {
          title: '商品列表',
          noCache: true
        }
      },
      {
        path: 'commodityShelves',
        component: () => import('@/views/goods/commodityShelves'),
        name: 'commodityShelves',
        meta: {
          title: '商品上架',
          noCache: true
        }
      },
      {
        path: 'commodityedit',
        component: () => import('@/views/goods/commodityedit'),
        name: 'commodityedit',
        meta: {
          title: '商品编辑',
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/activity',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'promotionManage',
    meta: {
      title: '推广管理',
      icon: 'message'
    },
    children: [
      {
        path: 'advertisement',
        component: () => import('@/views/activity/advertisement'),
        name: 'advertisement',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '广告管理',
          noCache: true
        }
      },
      {
        path: 'coupon',
        component: () => import('@/views/activity/coupon'),
        name: 'coupon',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '优惠卷管理',
          noCache: true
        }
      },
      {
        path: 'couponDetail',
        component: () => import('@/views/activity/couponDetail'),
        name: 'couponDetail',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '优惠卷详情',
          noCache: false
        }
      },
      {
        path: 'thematic',
        component: () => import('@/views/activity/thematic'),
        name: 'thematic',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '推广管理',
          noCache: true
        }
      },
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'sysManage',
    meta: {
      title: '系统管理',
      icon: 'system'
    },
    children: [
      {
        path: 'administrators',
        component: () => import('@/views/system/administrators'),
        name: 'administrators',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '管理员',
          noCache: true
        }
      },
      {
        path: 'role',
        component: () => import('@/views/system/role'),
        name: 'role',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '角色管理',
          noCache: true
        }
      },
      {
        path: 'storage',
        component: () => import('@/views/system/storage'),
        name: 'storage',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '对象存储',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/config',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'configManage',
    meta: {
      title: '配置管理',
      icon: 'peizhi'
    },
    children: [
      {
        path: 'information',
        component: () => import('@/views/config/information'),
        name: 'information',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '商城信息配置',
          noCache: true
        }
      },
      {
        path: 'configuration',
        component: () => import('@/views/config/configuration'),
        name: 'configuration',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '商城首页配置',
          noCache: true
        }
      },
      {
        path: 'allocation',
        component: () => import('@/views/config/allocation'),
        name: 'allocation',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '运费配置',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/thematic',
        component: () => import('@/views/activity/topicCreate'),
        name: '/thematic',
        meta: {
          // perms: ['GET /admin/brand/list'],
          title: '添加推广',
          noCache: true
        }
  },
  {

    path: '/topicEdit',
    component: () => import('@/views/activity/topicEdit'),
    name: '/thematic',
    meta: {
      // perms: ['GET /admin/brand/list'],
      title: '修改推广',
      noCache: true
    }
  },
  {
    path: '/profile',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    children: [
      {
        path: 'password',
        component: () => import('@/views/rePassword/index'),
        name: 'password',
        meta: { title: '修改密码', noCache: true }
      }
    ],
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
]
